import java.sql.*;
import java.util.Scanner;

public class Test2 {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		System.out.print("Input name:");
		String name = scanner.nextLine();
		try{
			Connection conn = JDBCUtil.getConnection();
			//Statement st = conn.createStatement();
			//String sql = "select * from Sample where Name='" + name +"'";
			String sql = "select *from Sample where Name=?";
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setString(1,name); //first ? is 1, not 0
			ResultSet rs = ps.executeQuery();
			//System.out.println(sql);
			//ResultSet rs = st.executeQuery(sql);
			while(rs.next()){  //Pointer
				System.out.println(rs.getString("Name")+"\t"+rs.getInt("Age"));
			}
			rs.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
